// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   BehaviorView.java

package jones.gui;

import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import jones.SimpleRobot;

public class BehaviorView extends JPanel
    implements Observer
{

    private static final int HISTORY = 30;
    private DefaultComboBoxModel model = null;
    private String lastBehaviorAdded = null;

    public BehaviorView()
    {
        model = new DefaultComboBoxModel();
        JComboBox comboBox = new JComboBox(((javax.swing.ComboBoxModel) (model)));
        javax.swing.border.Border border = ((javax.swing.border.Border) (new EmptyBorder(0, 5, 0, 5)));
        comboBox.setBorder(border);
        comboBox.setPreferredSize(new Dimension(120, 20));
        add(((java.awt.Component) (comboBox)), "Center");
    }

    public void update(Observable obs, Object obj)
    {
        SimpleRobot robot = (SimpleRobot)obs;
        jones.behavior.Behavior behavior = robot.getLastChosenBehavior();
        if (behavior == null)
            return;
        String lastChosenBehavior = ((Object) (behavior)).toString();
        if (lastChosenBehavior.equals(((Object) (lastBehaviorAdded))))
        {
            return;
        } else
        {
            lastBehaviorAdded = lastChosenBehavior;
            SwingUtilities.invokeLater(new Runnable() {

                public void run()
                {
                    if (model.getSize() == 30)
                        model.removeElementAt(0);
                    model.addElement(((Object) (lastBehaviorAdded)));
                    model.setSelectedItem(((Object) (lastBehaviorAdded)));
                }

            }
);
            return;
        }
    }


}
